package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.OaHumanRecruit;
import com.ruoyi.oa.domain.vo.OaHumanRecruitVo;
import com.ruoyi.oa.domain.bo.OaHumanRecruitBo;
import com.ruoyi.oa.service.IOaHumanRecruitService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 招聘申请
 *
 * @author ruoyi
 * @date 2023-06-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/humanRecruit")
public class OaHumanRecruitController extends BaseController {

    private final IOaHumanRecruitService iOaHumanRecruitService;

    /**
     * 查询招聘申请列表
     */
    @SaCheckPermission("oa:employeeInfo:list")
    @GetMapping("/list")
    public TableDataInfo<OaHumanRecruitVo> list(OaHumanRecruitBo bo, PageQuery pageQuery) {
        return iOaHumanRecruitService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出招聘申请列表
     */
    @SaCheckPermission("oa:employeeInfo:export")
    @Log(title = "招聘申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaHumanRecruitBo bo, HttpServletResponse response) {
        List<OaHumanRecruitVo> list = iOaHumanRecruitService.queryList(bo);
        ExcelUtil.exportExcel(list, "招聘申请", OaHumanRecruitVo.class, response);
    }

    /**
     * 获取招聘申请详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("oa:employeeInfo:query")
    @GetMapping("/{id}")
    public R<OaHumanRecruitVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iOaHumanRecruitService.queryById(id));
    }

    /**
     * 新增招聘申请
     */
    @SaCheckPermission("oa:employeeInfo:add")
    @Log(title = "招聘申请", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<OaHumanRecruitBo> add(@Validated(AddGroup.class) @RequestBody OaHumanRecruitBo bo) {
        return R.ok(iOaHumanRecruitService.insertByBo(bo));
    }

    /**
     * 修改招聘申请
     */
    @SaCheckPermission("oa:employeeInfo:edit")
    @Log(title = "招聘申请", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<OaHumanRecruit> edit(@Validated(EditGroup.class) @RequestBody OaHumanRecruitBo bo) {
        return R.ok(iOaHumanRecruitService.updateByBo(bo));
    }

    /**
     * 删除招聘申请
     *
     * @param ids 主键串
     */
    @SaCheckPermission("oa:employeeInfo:remove")
    @Log(title = "招聘申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iOaHumanRecruitService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
